local socket = require("socket")


package.path = package.path ..';../?.lua'
local tool = require('lib/tool')

local Client = tool.class('Client')
function Client:Ctor()

end

function Client:connect(host, port, timeout)
    self.socket = assert(socket.connect(host, port))
    self.socket:settimeout(timeout)
end

function Client:request(message,callBack)
    self.socket:send(message)
    local recvt, sendt, status
    recvt, sendt, status = socket.select({self.socket}, nil, 1)
    while #recvt > 0 do
        local response, receive_status = self.socket:receive()
        if receive_status ~= "closed" then
            if response then
                recvt, sendt, status = socket.select({self.socket}, nil, 1)
                print(response)
                callBack(response)
                return
            end
        else
            break
        end
    end
end

function Client:onRecevie(args)

end
return Client

